var xhEditor;
function initEditor(id) {
	var _Plugin={
		test7:{c:'testClassName',t:'保存远程图片',s:'ctrl+7',e:function(){
			var _this=this;
			_this.saveBookmark();
			downRemoteFile();
		}},
		Code:{c:'btnCode',t:'插入代码',h:1,e:function(){
			var _this=this;
			var htmlCode='<div><select id="xheCodeType"><option value="html">HTML/XML</option><option value="js">Javascript</option><option value="css">CSS</option><option value="php">PHP</option><option value="java">Java</option><option value="py">Python</option><option value="pl">Perl</option><option value="rb">Ruby</option><option value="cs">C#</option><option value="c">C++/C</option><option value="vb">VB/ASP</option><option value="">其它</option></select>起始行号：<input type="text" id="xheLine" value="1" size="4"></div><div><textarea id="xheCodeValue" wrap="soft" spellcheck="false" style="width:300px;height:100px;" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>';
			var jCode=$(htmlCode),jLine=$('#xheLine',jCode),jType=$('#xheCodeType',jCode),jValue=$('#xheCodeValue',jCode),jSave=$('#xheSave',jCode);
			jSave.click(function(){
				_this.loadBookmark();
				var param = jType.val();
				if(jLine.val()>1) param+=' num='+jLine.val();
				_this.pasteHTML('['+param+']'+jValue.val().replace(/\n/g,'<br />')+'[/'+jType.val()+']');
				_this.hidePanel();
				return false;	
			});
			_this.saveBookmark();
			_this.showDialog(jCode);
		}}
	};
	$('head').append('<style type="text/css">.testClassName {background:transparent url('+SITEURL+'/static/js/xheditor/xheditor_skin/default/img/plugin.gif) no-repeat 16px 16px;background-position:2px 2px;}.btnCode {background:transparent url('+SITEURL+'/static/js/xheditor/xheditor_skin/default/img/code.gif) no-repeat 16px 16px;background-position:2px 2px;}</style>');
	xhEditor=$('#'+id).xheditor({skin:'vista', plugins:_Plugin,tools:'mfull'});
}

function downRemoteFile() {
	var formObj = $("#articleform");
	var oldAction = formObj.attr('action');
	formObj.attr('action', "index.php?option=portalcp&task=upload&op=downremotefile");
	formObj.attr('onSubmit', "");
	formObj.attr('target', "uploadframe");
	formObj.submit();
	formObj.attr('action', oldAction);
	formObj.attr('target', '');
}

function insertImage(image, url) {
	url = typeof url == 'undefined' || url === null ? image : url;
	var html = '<p><a href="' + SITEURL+url + '" target="_blank"><img src="'+image+'"></a></p>';
	xhEditor.pasteHTML(html);
}
